package com.yuncheng.oaApi.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuncheng.annotation.AutoLog;
import com.yuncheng.oaApi.busService.OaDbrService;
import com.yuncheng.oaApi.busService.MyLcFlowService;
import com.yuncheng.oaApi.service.IOaSpcySqsxJobService;
import com.yuncheng.oaApi.service.impl.OaYcSysUserServiceImpl;
import com.yuncheng.utils.ThreadContextHelper;
import com.yuncheng.vo.CurrentUserVo;
import com.yuncheng.vo.HttpResult;
import com.yuncheng.oaApi.vo.OaFlowVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Api(tags = "OA我的待办接口")
@RestController
@RequestMapping("/api/spzx-oa/mydb")
public class MyLcFlowController {
    private static final Logger log = LoggerFactory.getLogger(MyLcFlowController.class);

    @Resource
    private OaYcSysUserServiceImpl ycSysUserService;

    @Resource
    private MyLcFlowService myLcFlowService;

    @Resource
    @Lazy
    private OaDbrService oaDbrService;

    @Resource
    @Lazy
    private IOaSpcySqsxJobService spcySqsxJobService;

    /**
     * 获取个人相关-所有类型的流程待办
     */
    @AutoLog(value = "获取个人相关-所有类型的流程待办")
    @ApiOperation(value = "获取个人相关-所有类型的流程待办")
    @GetMapping(value = "queryAlloaFlowJob")
    public HttpResult<?> queryAlloaFlowJob() {
        Map map = new HashMap(); // 结果集 map
        Map LgqsMap = new HashMap(); // 离岗流程 map
        Map XzswMap = new HashMap(); // 行政事务 map
        Map XcxxwMap = new HashMap(); // 宣传信息 map
        Map HysglMap = new HashMap(); // 会议室管理 map
        Map BgypsqglMap = new HashMap(); // 办公用品申请管理 map
        Map jbzbMap = new HashMap(); // 加班值班申请管理 map
        Map qxjMap = new HashMap(); // 请休假申请管理 map
        Map yybzx = new HashMap(); // 预约表咨询 map

        Map ListMap = new HashMap<>();

        CurrentUserVo user = ThreadContextHelper.getCurrentUser();
        if (user == null) {
            return HttpResult.error("请重新登录，Token已失效！");
        }
        boolean onlyCurrentUser = true; // 查询个人
        Integer pageNo = 1;
        Integer pageSize = 1000;
        Page<OaFlowVo> page = new Page<>(pageNo, pageSize);
        /*********************************************【  OA - 各科室 - 流程待办】**************************************/
        LgqsMap.putAll(myLcFlowService.myLgqsFlowDb(page, onlyCurrentUser, user));
        XzswMap.putAll(myLcFlowService.myXzswspFlowDb(page, onlyCurrentUser, user));
        XcxxwMap.putAll(myLcFlowService.myXcxxFlowDb(page, onlyCurrentUser, user));
        HysglMap.putAll(myLcFlowService.myhysglFlowDb(page, onlyCurrentUser, user));
        BgypsqglMap.putAll(myLcFlowService.mybgypsplFlowDb(page, onlyCurrentUser, user));
        jbzbMap.putAll(myLcFlowService.myjbzblFlowDb(page, onlyCurrentUser, user));
        qxjMap.putAll(myLcFlowService.myqxjFlowDb(page, onlyCurrentUser, user));


        map.put("oalgqs", LgqsMap);
        map.put("oaxzswsp", XzswMap);
        map.put("oaxcxxsp", XcxxwMap);
        map.put("oahysgl", HysglMap);
        map.put("oabgypsqgl", BgypsqglMap);
        map.put("oajbzb", jbzbMap);
        map.put("oaqxj", qxjMap);

        map.put("oalgqslist", myLcFlowService.myLgqsList(onlyCurrentUser, user));
        map.put("oaxzswsplist", myLcFlowService.myXzswspList(onlyCurrentUser, user));
        map.put("oaxcxxsplist", myLcFlowService.myXcxxList(onlyCurrentUser, user));
        map.put("oahysgllist", myLcFlowService.myhysList(onlyCurrentUser, user));
        map.put("oabgypsqgllist", myLcFlowService.mybgypList(onlyCurrentUser, user));
        map.put("oajbzblist", myLcFlowService.myjbzbList(onlyCurrentUser, user));
        map.put("oaqxjlist", myLcFlowService.myqxjList(onlyCurrentUser, user));

        return HttpResult.ok(map);
    }


}
